package von.seiji.cn.other;


import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.junit.Test;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: SeiJi
 * @DateTime: 2022/2/9 10:31
 * @Description: 此人很懒，未写描述！
 **/
public class PinYinT {

    @Test
    public void alfdi() {
        String[] as = PinyinHelper.toHanyuPinyinStringArray('a');
        System.out.println("as = " + as);
        System.out.println("/".toUpperCase());
    }

    @Test
    public void aldslk() throws BadHanyuPinyinOutputFormatCombination {
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        String string = PinyinHelper.toHanyuPinyinString("*#123我们来看 SDK", format, "+");
        System.out.println("string = " + string);
    }


    @Test
    public void dlsa() {
        List<String> list = Lists.newArrayList("a", "z", "12321", "*#", "扣篮大赛", "看电视", "仍无法", "卡卡罗特", "欧老师", "奥德赛", "平顶山了", "八点", "哈迪斯", "女孩");

        list.sort(Comparator.naturalOrder());
        System.out.println(list);

        System.out.println(new TreeSet<String>(list));

//        list.sort(Comparator.comparing(item -> PinyinHelper.toHanyuPinyinStringArray(item.charAt(0))[0].toUpperCase().charAt(0)));

//        System.out.println("list = " + list);

        Map<String, List<String>> collect = list.stream().collect(Collectors.groupingBy(item
                        ->
                {

                    if (StrUtil.isBlank(item)) {
                        return "#";
                    } else {
                        char c = item.charAt(0);
                        if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
                            return String.valueOf(c).toUpperCase();
                        }
                        try {
                            String[] array = PinyinHelper.toHanyuPinyinStringArray(c);
                            return array[0].substring(0, 1).toUpperCase();
                        } catch (Exception e) {
                            return "#";
                        }
                    }
                }
                ,
                Collectors.collectingAndThen(Collectors.toList(), item -> item.stream().sorted().collect(Collectors.toList()))
                )
        );


        System.out.println("collect = " + collect);

        String[] s = PinyinHelper.toHanyuPinyinStringArray('女');
        System.out.println("你s0 = " + Arrays.toString(s));


        /*
        String[] s1 = PinyinHelper.toGwoyeuRomatzyhStringArray('你');
        System.out.println("你s1 = " + Arrays.toString(s1));
        String[] s2 = PinyinHelper.toMPS2PinyinStringArray('你');
        System.out.println("你s2 = " + Arrays.toString(s2));
        String[] s3 = PinyinHelper.toTongyongPinyinStringArray('你');
        System.out.println("你s3 = " + Arrays.toString(s3));
        String[] s4 = PinyinHelper.toWadeGilesPinyinStringArray('你');
        System.out.println("你s4 = " + Arrays.toString(s4));
        String[] s5= PinyinHelper.toYalePinyinStringArray('你');
        System.out.println("你s5 = " + Arrays.toString(s5));*/
    }

    @Test
    public void dlsa1() {
        List<String> list = Lists.newArrayList("a", "z", "12321", "*#", "扣篮大赛", "看电视", "仍无法", "卡卡罗特", "欧老师", "奥德赛", "平顶山了", "八点", "哈迪斯", "女孩");

        list.sort(Comparator.naturalOrder());
        System.out.println(list);

        System.out.println(new TreeSet<String>(list));

//        list.sort(Comparator.comparing(item -> PinyinHelper.toHanyuPinyinStringArray(item.charAt(0))[0].toUpperCase().charAt(0)));

//        System.out.println("list = " + list);

        Map<Character, List<String>> collect = list.stream().collect(Collectors.groupingBy(item
                        ->
                {

                    if (StrUtil.isBlank(item)) {
                        return '#';
                    } else {


                        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
                        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
                        try {
                            String string = PinyinHelper.toHanyuPinyinString(item.substring(0, 1), format, "");
                            char c = string.charAt(0);
                            if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
                                return Character.toUpperCase(c);
                            }
                        } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
                        }
                        return '#';

                    }
                }
                ,
                Collectors.collectingAndThen(Collectors.toList(), item -> item.stream().sorted().collect(Collectors.toList()))
                )
        );


        System.out.println("collect = " + collect);

        List<HashMap<String, Object>> mapList = collect.entrySet().stream().map(item -> {
            HashMap<String, Object> map = Maps.newHashMap();
            map.put("letter", item.getKey());
            map.put("data", item.getValue());
            return map;
        }).sorted(Comparator.comparing(item -> (char)item.get("letter")))
                .collect(Collectors.toList());
        System.out.println("mapList = " + mapList);


        /*
        String[] s1 = PinyinHelper.toGwoyeuRomatzyhStringArray('你');
        System.out.println("你s1 = " + Arrays.toString(s1));
        String[] s2 = PinyinHelper.toMPS2PinyinStringArray('你');
        System.out.println("你s2 = " + Arrays.toString(s2));
        String[] s3 = PinyinHelper.toTongyongPinyinStringArray('你');
        System.out.println("你s3 = " + Arrays.toString(s3));
        String[] s4 = PinyinHelper.toWadeGilesPinyinStringArray('你');
        System.out.println("你s4 = " + Arrays.toString(s4));
        String[] s5= PinyinHelper.toYalePinyinStringArray('你');
        System.out.println("你s5 = " + Arrays.toString(s5));*/
    }


    @Test
    public void faljdioj() {
        ArrayList<String> strings = Lists.newArrayList("扣篮大赛", "看电视", "卡卡罗特");

        try {
            int a = 1 / 0;
        } catch (Exception e) {
            e.printStackTrace();


            System.out.println("========================");
            System.out.println(e);
            System.out.println(
                    Lists.asList(e, e.getStackTrace()).toString());
        }
        strings.sort(Comparator.naturalOrder());
        System.out.println("strings = " + strings);
    }
}
